package controller

import (
	"webstack/model"

	"github.com/gin-gonic/gin"
)

func AddSearchEngines(c *gin.Context) {
	var m model.SearchEngines
	c.ShouldBind(&m)
	id, err := m.Add()
	if err != nil {
		c.JSON(200, gin.H{"id": 0, "errCode": 10, "errMsg": err.Error()})
	} else {
		c.JSON(200, gin.H{"id": id, "errCode": 0, "errMsg": ""})
	}
}

func DeleteSearchEngines(c *gin.Context) {
	var m model.SearchEngines
	c.ShouldBind(&m)
	err := model.DeleteSearchEngines(m.ID)
	if err != nil {
		c.JSON(200, gin.H{"errCode": 25, "errMsg": err.Error()})
	} else {
		c.JSON(200, gin.H{"errCode": 0, "errMsg": ""})
	}
}

func UpdateSearchEngines(c *gin.Context) {
	var m model.SearchEngines
	c.ShouldBind(&m)
	err := m.Update()
	if err != nil {
		c.JSON(200, gin.H{"errCode": 36, "errMsg": err.Error()})
	} else {
		c.JSON(200, gin.H{"errCode": 0, "errMsg": ""})
	}
}
